﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>KAKA摄影</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <style>
        @-webkit-keyframes spin {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }

        @keyframes spin {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }

        .page-loading {
            width: 100%;
            height: 100%;
            background-color: #fff;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1;
            overflow: hidden;
        }

        .loader {
            border: 3px solid #ddd;
            -webkit-animation: spin 1s linear infinite;
            animation: spin 1s linear infinite;
            border-top: 3px solid #000;
            border-radius: 50%;
            width: 30px;
            height: 30px;
            top: 50%;
            left: 50%;
            position: absolute;
            margin: -25px 0 0 -25px;
        }


        body {
            margin: 0px;
            padding: 0px;
        }

        .titleContent {
            padding: 10px 0px;
            background-color: rgba(0,0,0,0.8);
            border-bottom: 1px solid #ddd;
            margin: 0px;
            position: fixed;
            top: 0px;
            width: 100%;
            min-height: 18px;
            z-index:999;
        }

        #title {
            background-image: url(../images/back.png);
            background-repeat: no-repeat;
            color: #fff;
            font-size: 16px;
            text-align: center;
            font-weight: bold;
            height: 18px;
        }

        #content {
            overflow: hidden;
            padding: 2px;
            margin-top: 40px;
            overflow-x: hidden;
            padding: 0px 5px;
        }

        .is-loading {
            background-color: #fff;
            background-image: url(images/load.gif);
            background-repeat: no-repeat;
            background-position: center;
            border-radius: 3px;
            border: 1px solid #ddd;
            padding: 3px;
            background-color: #eee;
        }

      

        .msg {
            text-align: center;
            color: #888;
            font-size: 12px;
            padding: 5px;
            display: none;
        }

        .more {
            text-align: center;
            padding: 10px;
            color: #ff0000;
            border: 1px solid #eee;
            margin-top: 5px;
        }

        .item {
            margin-top: 10px;
            overflow: hidden;
            position: relative;
			padding-bottom:10px;
			border-bottom:1px solid #eee;
			min-height:100px;
			background-image: url(../images/load.gif);
            background-repeat: no-repeat;
            background-position: center;
        }

        .item_flag {
            padding: 5px;
            background-color: rgba(254, 255, 254,0.5);
            border: 1px solid #ddd;
            border-radius: 3px;
            color: #FF5722;
            max-width: 60px;
            position: absolute;
            top: 10px;
            right: 10px;
        }

        .item_content {
            position: absolute;
            background-color: rgba(254, 255, 254,0.5);
            bottom: 10px;
            height: 84px;
            width: 100%;
            text-align: center;
        }

        .item_title {
            font-size: 16px;
            font-weight: bold;
            padding: 5px;
            border-bottom:0px solid #ddd;
            width:90%;
            margin:0px auto;
        }

        .item_text {
            line-height: 22px;
            color: #fff;
            overflow: hidden;
        }
    </style>
</head>
<body>

    <div class="page-loading">
        <div class="loader"></div>
    </div>
    <div class="titleContent" onclick="window.history.back();">
        <div id="title">
            作品欣赏
        </div>
    </div>

    <div id="content">
        <div id="newContent">
          
        </div>
        <div class="msg">加载中……</div>
        <div class="more">显示更多</div>
    </div>

    <script src="/js/lib/jquery.js"></script>
    <script type="text/javascript">
        var pageIndex = 0;
        var busy = 0;
        var resultList = [];
        function getproductList() {
            if (busy == 2) return;
            busy = 1;
            pageIndex++;

            var Jsondata = {};
            Jsondata.pageIndex = pageIndex;
            Jsondata.pageSize = 3;

            $.post('/admin/getproducts', JSON.stringify(Jsondata), function (response) {
                if (response.length == 0) {
                    $(".more").hide();
                    busy = 2;
                    return;
                }
                $(".msg").show();
                var template = ' <div class="item">'
                + '<div><img src="../files/upload/small/{{image}}" style="width:100%;" onclick="imgClick(\'{{id}}\')" /> </div>'
                +'<div class="item_flag">{{count}}张</div>'
                +'<div class="item_content">'
                +'<div class="item_title">{{title}}</div>'+'<div class="item_text">{{content}}</div>'
                +'</div>'
                + '</div>';

                var template2 = ' <div class="item">'
                + '<div><img src="../files/upload/small/{{image}}" style="width:100%;"  onclick="imgClick(\'{{id}}\')"  /> </div>'
                + '<div class="item_flag">{{count}}张</div>'
                + '</div>';
               
                var resultHTML = "";
                for (i = 0; i < response.length; i++) {                    
                    var o = response[i];
                    resultList.push(o);
                    var tempHtml = template2;
                    if (o.title != "") tempHtml = template;
                    tempHtml = tempHtml.replace("{{id}}", o._id);
                    tempHtml = tempHtml.replace("{{image}}", o.filename);
                    tempHtml = tempHtml.replace("{{count}}", o.images.length.toString());
                    tempHtml = tempHtml.replace("{{title}}", o.title);
                    tempHtml = tempHtml.replace("{{content}}", o.description);
                    resultHTML += tempHtml;
                }
                $("#newContent").append(resultHTML);
                $('.page-loading').delay(0).fadeOut(1000);
                $(".msg").hide();
                busy = 0;
                console.log(resultList);
            })
        }

        function imgClick(id) {
            var o=null;
            for (i = 0; i < resultList.length; i++) {
                if (id == resultList[i]._id) o = resultList[i];
            }
            alert(id);
            console.log(o);
            return false;
        }
        $(function () {
            $('.page-loading').delay(0).fadeOut(1000);
            getproductList();

            $(".more").click(function () { getnewsList();});
            $(window).bind("scroll", function (e) {
                var ScrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
                if (busy == 2) return;
                if (ScrollBottom < 100) {
                    if (busy == 1) return;
                    getproductList();
                }
            })
        });
    </script>

</body>

</html>
